#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

void PrintTable(int* table, int size)
{
	cout << endl;
	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < size; j++)
		{
			cout << table[i*size + j] << " ";
		}
		cout << endl;
	}
}

void Copy(int* table, int tableSourceRow, int tableSourceCol, int tableDestinationRow, int tableDestinationCol, int size, const int number)
{
	for (int iS = tableSourceRow, iD = tableDestinationRow; iS < tableSourceRow + size && iD < tableDestinationRow + size; iS++, iD++)
	{
		for (int jS = tableSourceCol, jD = tableDestinationCol; jS < tableSourceCol + size && jD < tableDestinationCol + size; jS++, jD++)
		{
			table[iD*number + jD] = table[iS*number + jS];
		}
	}
}

void RoundRobinScheduleNonR(int* table, int size)
{
	int count = 1;
	for (int i = 0; i < size; i++)
	{
		table[i] = count++;
	}
	for (int i = 1; i < size; i *= 2)
	{
		for (int j = 0; j < size; j+=i*2)
		{
			Copy(table, 0, j, i, j + i, i, size);
			Copy(table, 0, i + j, i, j, i, size);
		}
	}
}

int main()
{
	int number;
	cout << "Please input tne number of participants:>";
	do
	{
		cin >> number;
		if (number % 2 == 0)
			break;
		else
			cout << "Input fail,please input again:>" << endl;
	} while (1);

	int* table = new int[number*number];
	RoundRobinScheduleNonR(table, number);
	PrintTable(table, number);
	return 0;
}